package com.alifi.crm.web.home.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import net.sf.json.JSONObject;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.common.lang.StringUtil;
import com.alibaba.common.logging.Logger;
import com.alibaba.common.logging.LoggerFactory;
import com.alifi.crm.dal.lottery.AmountDAO;
import com.alifi.crm.dal.object.AmountDO;

/**
 * 
 * 
 * @author wb_liangzhou.yan
 * @version $Id: LotteryAction.java, v 0.1 2013-4-24 下午07:03:40 wb_liangzhou.yan Exp $
 */
public class AmountAction {
    
    protected static final Logger      logger = LoggerFactory.getLogger(AmountAction.class);
    
    @Autowired
    private AmountDAO amountDAO;
    
    /**
     * @param request
     * @param response
     * @param ctx
     */
    public void doGetAmount(HttpServletRequest request, HttpServletResponse response,Navigator nav,final Context ctx){
            String employeeNum = request.getParameter("employeeNum");
            if(StringUtil.isBlank(employeeNum)){
                return;
            }
            AmountDO amountDO = amountDAO.getAmount(employeeNum.trim());
            int status = 3;
            int amount = 0;
            if(amountDO != null){
                if(amountDO.getCreditAmount() != null){
                    status = 1;
                    amount = amountDO.getCreditAmount().intValue();
                }else if(amountDO.getPreAmount() != null){
                    status = 2;
                    amount = amountDO.getPreAmount().intValue();
                }
            }
            
            JSONObject json = new JSONObject();
            json.put("status", status);
            json.put("amount", amount);
            try {
                response.getWriter().println(json.toString());
            } catch (IOException e) {
                logger.error("IOException", e);
            }
    }
    
    
    
}
